package com.zhuozhengsoft.pageoffice6springboot2back.controller;

import com.zhuozhengsoft.pageoffice.FileSaver;
import com.zhuozhengsoft.pageoffice.OpenModeType;
import com.zhuozhengsoft.pageoffice.PageOfficeCtrl;
import com.zhuozhengsoft.pageoffice.word.WordDocumentWriter;
import com.zhuozhengsoft.pageoffice6springboot2back.util.GetDirPathUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping(value = "/FormToDataRegions")
public class FormToDataRegions {

    //获取doc目录的磁盘路径
    private final String dir = GetDirPathUtil.getDirPath() + "static/doc/";

    public FormToDataRegions() throws IOException {
    }


    @RequestMapping(value = "/Word")
    public String showWord(HttpServletRequest request) {
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        WordDocumentWriter doc = new WordDocumentWriter();
        doc.openDataRegion("PO_Buyer").setEditing(true);
        doc.openDataRegion("PO_Company").setEditing(true);
        doc.openDataRegion("PO_Supplier").setEditing(true);
        doc.openDataRegion("PO_code").setEditing(true);
        doc.openDataRegion("PO_rmb").setEditing(true);
        doc.openDataRegion("PO_table").setEditing(true);
        poCtrl.setWriter(doc);
        //打开文档
        poCtrl.webOpen("/doc/FormToDataRegions/test.docx", OpenModeType.docSubmitForm, "张三");
        return poCtrl.getHtml();
    }


    @RequestMapping("save")
    public void save(HttpServletRequest request, HttpServletResponse response) {
        FileSaver fs = new FileSaver(request, response);
        fs.saveToFile(dir + "FormToDataRegions/" + fs.getFileName());
        fs.close();
    }
}

